package tech.wetech.admin3.controller;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tech.wetech.admin3.sys.service.EmailService;
import tech.wetech.admin3.util.CustomResponse;


@RestController
@RequestMapping("/email")
public class AooEmailController {
  @Autowired
  private EmailService emailService;

  @PostMapping("/getcode")
  public ResponseEntity<?> getcode(@RequestParam("email") String email){
    String code = emailService.getCode(email);
    return ResponseEntity.ok(new CustomResponse.r1("发送成功", true, code));
  }

  @PostMapping("/verifyCode")
  public ResponseEntity<?> verifyCode(@RequestParam String email, @RequestParam String code) {
    boolean flag = emailService.verifyCode(email, code);
    if (flag) {
      return ResponseEntity.ok(new CustomResponse.r1("邮箱验证码正确", true, ""));
    } else {
      return ResponseEntity.ok(new CustomResponse.r1("邮箱验证码错误或已过期", false, ""));
    }
  }

}
